package com.feshfans.controller.eventhandler;

import com.feshfans.controller.Controller;
import com.feshfans.controller.RegisteredController;
import javafx.event.EventHandler;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;


public abstract class AbstractEventHandler<M,N> implements EventHandler<WindowEvent> {

    protected M m;
    protected N n;

    public AbstractEventHandler(M m,N n){
        this.m = m;
        this.n = n;
    }

    @Override
    public void handle(WindowEvent event) {
        // 获取保存的 controller
        Object obj = getStage().getUserData();
        if(obj!=null){
            Controller controller =(Controller)obj;
            if(controller instanceof RegisteredController){
                ((RegisteredController) controller).unregister();
            }
        }
        remove();
    }

    public abstract void remove();
    public abstract Stage getStage();
}
